package com.by.toolkit.enums;

import com.by.toolkit.consts.RedisConst;
import com.by.toolkit.utils.SplitterUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public enum RedisCacheEnum {

    PROJECTID_CORP_CODE(RedisCacheEnum.PROJECTID_CORP_CODE_CODE, "企业代码", 60L * 24 * 7),
    PROJECT_CODE_RELA_ID(RedisCacheEnum.PROJECT_CODE_RELA_ID_CODE, "项目代码", 60L * 24 * 7),
    COURSE_CATEGORY(RedisCacheEnum.COURSE_CATEGORY_CODE, "课程分类", 60L * 24 * 7),
    VIRTUAL_SERVICE(RedisCacheEnum.VIRTUAL_SERVICE_CODE, "虚拟服务", 60L * 24 * 7),
    OPERATE_WX_MP(RedisCacheEnum.OPERATE_WX_MP_CODE, "运营的微信公众号", 60L * 24 * 7),
    PROMOTION_WX_MINI_APP(RedisCacheEnum.PROMOTION_WX_MINI_APP_CODE, "推广接量的微信小程序", 60L * 24 * 7),
    DEFAULT_AVATAR(RedisCacheEnum.DEFAULT_AVATAR_CODE, "默认头像", 60L * 24 * 7),
    COURSE_CURRICULUM_INFO(RedisCacheEnum.COURSE_CURRICULUM_INFO_CODE, "班级课程信息", 60L * 24 * 7),
    ORDER_INFO(RedisCacheEnum.ORDER_INFO_CODE, "订单信息", 60L),
    CHAIN_INFO_CACHE(RedisCacheEnum.CHAIN_INFO_CACHE_CODE, "投放链路信息", 2 * 60L),
    SPU_INFO_CACHE(RedisCacheEnum.SPU_INFO_CACHE_CODE, "spu信息", 60L * 24 * 7),
    SKU_INFO_CACHE(RedisCacheEnum.SKU_INFO_CACHE_CODE, "sku信息", 60L * 24 * 7),
    SPU_DEPOSIT_PROGRAMME(RedisCacheEnum.SPU_DEPOSIT_PROGRAMME_CACHE_CODE, "spu定金", 60L * 24 * 7),
    COURSE_GROUP(RedisCacheEnum.COURSE_GROUP_CODE, "课程分组", 60L * 24 * 7),
    ;

    private Integer code;
    private String desc;

    private Long expireMinutes;

    private static final Map<Integer, RedisCacheEnum> MAP = Arrays.stream(RedisCacheEnum.values()).collect(Collectors.toMap(RedisCacheEnum::getCode, Function.identity()));

    public static RedisCacheEnum resolve(Integer code) {
        return MAP.get(code);
    }

    public static String buildKey(String dataId, Integer dataType) {
        return SplitterUtil.EN_COLON_JOINER.join(RedisConst.REDIS_CACHE_PREFIX, dataType, dataId);
    }


    public static final int PROJECTID_CORP_CODE_CODE = 1;
    public static final int PROJECT_CODE_RELA_ID_CODE = 2;
    public static final int COURSE_CATEGORY_CODE = 3;
    public static final int VIRTUAL_SERVICE_CODE = 4;
    public static final int OPERATE_WX_MP_CODE = 5;
    public static final int PROMOTION_WX_MINI_APP_CODE = 6;
    public static final int DEFAULT_AVATAR_CODE = 7;
    public static final int COURSE_CURRICULUM_INFO_CODE = 10;
    public static final int ORDER_INFO_CODE = 11;
    public static final int CHAIN_INFO_CACHE_CODE = 12;
    public static final int SPU_INFO_CACHE_CODE = 13;
    public static final int SKU_INFO_CACHE_CODE = 14;
    public static final int SPU_DEPOSIT_PROGRAMME_CACHE_CODE = 15;
    public static final int COURSE_GROUP_CODE = 16;

}
